<template>
  <div>
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
      <el-form-item label="" prop="stu_name">
        <el-input v-model="formData.stu_name" placeholder="请输入" clearable prefix-icon='el-icon-user-solid'
          :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="" prop="stu_email">
        <el-input v-model="formData.stu_email" placeholder="请填写正确的邮箱" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="" prop="stu_wechat">
        <el-input v-model="formData.stu_wechat" placeholder="请填写正确的微信否则老师无法联系你" clearable
          :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="" prop="stu_phone">
        <el-input v-model="formData.stu_phone" placeholder="请填写正确的电话否则老师无法联系你" clearable
          :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="" prop="class_id">
        <el-select v-model="formData.class_id" placeholder="请选择班级" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in class_idOptions" :key="index" :label="item.className"
            :value="item.id" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <div class="block" align="center">
        <span class="demonstration"></span>
        <el-date-picker
          v-model="formData.reservation_time"
          type="datetime"
          placeholder="选择日期时间">
        </el-date-picker>
      </div>
      <el-form-item label="" prop="question_id">
        <el-select v-model="formData.question_id" placeholder="请选择问题类型" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in question_idOptions" :key="index" :label="item.label"
            :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="teacher_id">
        <el-select v-model="formData.teacher_id" placeholder="请选择意向老师" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in teacher_idOptions"
                     :key="index"
                     :label="item.teacherName"
                     :value="item.id"
                     :disabled="item.disabled">
            <span style="float: left">{{item.teacherName}}</span>
            <span style="float: right">{{item.telephone}}</span>
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="question_describle">
        <el-input v-model="formData.question_describle" type="textarea" placeholder="请输入问题描述"
          :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>

import {findClass} from "@/api/reservation";
import {findTeacher} from "@/api/reservation";

export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        stu_name: undefined,
        stu_email: undefined,
        stu_wechat: undefined,
        stu_phone: undefined,
        class_id: undefined,
        reservation_time: undefined,
        question_id: undefined,
        teacher_id: undefined,
        question_describle: undefined,
      },
      rules: {
        stu_name: [{
          required: true,
          message: '请输入',
          trigger: 'blur'
        }],
        stu_email: [{
          required: true,
          message: '请填写正确的邮箱',
          trigger: 'blur'
        }],
        stu_wechat: [{
          required: true,
          message: '请填写正确的微信否则老师无法联系你',
          trigger: 'blur'
        }],
        stu_phone: [{
          required: true,
          message: '请填写正确的电话否则老师无法联系你',
          trigger: 'blur'
        }],
        class_id: [{
          required: true,
          message: '请选择班级',
          trigger: 'change'
        }],
        reservation_time: [{
          required: true,
          message: '请选择预约时间',
          trigger: 'blur'
        }],
        question_id: [{
          required: true,
          message: '请选择问题类型',
          trigger: 'change'
        }],
        teacher_id: [{
          required: true,
          message: '请选择意向老师',
          trigger: 'change'
        }],
        question_describle: [],
      },
      class_idOptions: [],
      question_idOptions: [{
        "label": "选项一",
        "value": 1
      }, {
        "label": "选项二",
        "value": 2
      }],
      teacher_idOptions: [],
    }
  },
  computed: {},
  watch: {},
  created() {
    this.findClassList();
    this.findTeacherList();
  },
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        // TODO 提交表单
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
    findClassList() {
      findClass().then(res=>{
        console.log(res.rows)
        this.class_idOptions=res.rows;
        console.log(this.class_idOptions)
      })
    },
    findTeacherList() {
      findTeacher().then(res=>{
        console.log(res.rows)
        this.teacher_idOptions=res.rows;
        console.log(this.class_idOptions)
      })
    },
  }
}

</script>
<style>
</style>
